<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改工作安排')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-arrange-edit" th:object="${workArrange}" >
            <h4 class="form-header h4">修改工作安排</h4>
            <input name="arrangeId" th:field="*{arrangeId}" class="form-control" type="hidden">
            <input id="userIds" name="userIds" th:field="*{userIds}" class="form-control" type="hidden">
            <input name="status" th:field="*{status}" class="form-control" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">填报表单：</label>
                <div class="col-sm-8">
                    <select name="templateId" class="form-control select2" required>
                        <option th:each="dict : ${templates}" th:text="${dict.templateName}" th:value="${dict.templateId}" th:field="*{templateId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">工作分类：</label>
                <div class="col-sm-8">
                    <select name="workCategory" th:field="*{workCategory}" class="form-control noselect2" th:with="type=${@dict.getType('work_category')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">工作标题：</label>
                <div class="col-sm-8">
                    <input name="arrangeTitle" th:field="*{arrangeTitle}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">发布范围：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <span class="input-group-addon"><a onclick="javaScript:chooseAllUser();">全员</a></span>
                        <span class="input-group-addon"><a onclick="javaScript:chooseUser();">选择</a></span>
                        <input id="releaseScope" name="releaseScope" th:field="*{releaseScope}" class="form-control" type="text" required>
                        <span class="input-group-addon"><a onclick="javaScript:clearUser();">清空</a></span>
                    </div>
                    
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">参与人数：</label>
                <div class="col-sm-8">
                    <input id="total" name="total" th:field="*{total}" class="form-control" type="number" unselectable="on" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">开始日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="startDate" th:value="*{#dates.format(startDate, 'yyyy-MM-dd')}" class="form-control" placeholder="格式：yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">结束日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="endDate" th:value="*{#dates.format(endDate, 'yyyy-MM-dd')}" class="form-control" placeholder="格式：yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">预警日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="warningDate" th:value="*{#dates.format(warningDate, 'yyyy-MM-dd')}" class="form-control" placeholder="格式：yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">站内提示：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('is_tips')}">
                        <input type="radio" th:id="${'websiteTips_' + dict.dictCode}" name="websiteTips" th:value="${dict.dictValue}" th:field="*{websiteTips}">
                        <label th:for="${'websiteTips_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">短信提示：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('is_tips')}">
                        <input type="radio" th:id="${'smsTips_' + dict.dictCode}" name="smsTips" th:value="${dict.dictValue}" th:field="*{smsTips}">
                        <label th:for="${'smsTips_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
        <div class="row">
            <div class="col-sm-offset-5 col-sm-10">
                <button type="button" class="btn btn-sm btn-success" onclick="submitHandler('1')"><i class="fa fa-plus"></i>暂 存</button>&nbsp;
                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler('2')"><i class="fa fa-check"></i>发 布</button>&nbsp;
                <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭</button>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "work/arrange"
        $("#form-arrange-add").validate({
            focusCleanup: true
        });

        function submitHandler(status) {
            var old_status = $('#status').val()
            if(old_status != 1){
                $.modal.alertWarning("该工作安排已执行，不能操作");
                return;
            }
            if ($.validate.form()) {
                $('#status').val(status)
                $.operate.save(prefix + "/edit", $('#form-arrange-edit').serialize());
            }
        }

        $("input[name='startDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='endDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='warningDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        
        function chooseAllUser(){
            $("#releaseScope").val(page_constants.ALL_USER)
            $.ajax({
				type : "POST",
				url : ctx + "common/activeUserCount",
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
                    $("#total").val(data.data);
				}
			});
        }

        function chooseUser(){
            $.modal.open("选择用户", ctx + "common/chooseUser");
        }

        function clearUser(){
            $("#releaseScope").val("");
            $("#total").val(0);
        }
    </script>
</body>
</html>